/**
 * 
 */
package org.youisoft.summer.evaluator.function.control;
import org.youisoft.summer.evaluator.context.CalContext;
import org.youisoft.summer.evaluator.function.AbstractFunction;
import org.youisoft.summer.evaluator.operator.Operator;
import org.youisoft.summer.evaluator.operator.base.ListOperator;

/**
 * @author zijiang.jl
 *
 */
public class ChainFunction extends AbstractFunction{

	@Override
	public <C,R,P> Operator<?> doInvoke(CalContext<C,R,P> context,Operator<?>... operator) {
		if(operator.length==0) return Operator.nullInstance;
		if(operator.length==1) return operator[0];
		ListOperator<Operator<?>> lo=null;
		for(Operator<?> o:operator){
			if(o.value()!=null){
				if(lo==null) lo=new ListOperator<Operator<?>>();
				lo.addOperator(o);
			}
		}
		return lo;
	}

}